/**
 * $Id: Organisation.java 6 2011-03-09 07:12:48Z r.middel@gmail.com $
 * 
 * Copyright (C) 2010 mrBussy.eu
 * 
 * WickedHRM is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * WickedHRM is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package eu.mrbussy.applications.wickedhrm.data;

import java.util.ArrayList;
import java.util.Collection;

import eu.mrbussy.applications.wickedhrm.data.OrganizationalUnit.OrganizationUnitType;

/**
 * @author KLC31471
 *
 */
public class Organisation {

	public void add(Organisation child) { this.addOrganization(child); }
	public void add(OrganizationalUnit child) { this.addDepartment(child); }
	
	private Collection<Organisation> children;
	private void addOrganization(Organisation child) { this.children.add(child); }
	public Collection<Organisation> getChildren() { return this.children; }
	
	private Organisation parent;
	public void setParent(Organisation parent) { this.parent =  parent; }
	public Organisation getParent() { return this.parent; }

	private String name;
	public String getName() { return this.name;}
	public void setName(String name) { this.name = name; }
	
	private Collection<OrganizationalUnit> departments;
	public OrganizationalUnit addDepartment(String name) {
		OrganizationalUnit retVal =new OrganizationalUnit(name, OrganizationUnitType.HIERARCHY, this); 
		this.departments.add(retVal);
		return retVal;
	}
	private OrganizationalUnit addDepartment(OrganizationalUnit dep) {
		this.departments.add(dep);
		return dep;
	}
	public Collection<OrganizationalUnit> getDepartments() { return this.departments; }
	
	/**
	 * 
	 */
	public Organisation(String name) {
		this.departments = new ArrayList<OrganizationalUnit>();
		this.children = new ArrayList<Organisation>();
		this.setName(name);
	}

	@Override
	public String toString() {
		return this.getName();
	}
	@Override
	public int hashCode() {
		return this.getName().hashCode() + super.hashCode();
	}
	
	public boolean hasDepartments() {
		 return this.departments == null ? false : this.departments.size()>0;
	}
	public boolean hasChildren() {
		 return this.children == null ? false : this.children.size()>0;
	}
}
